import kashgari
import re
import Util.util as util
loadedmodel = kashgari.utils.load_model(r"E:\project_python\NewN\en(BiLSTM_CRF_Model)")
allFileTxt = open(r"C:\Users\Lenovo\Desktop\txt2\allTxt.txt",'r',encoding="UTF-8")
outFile = open(r'E:\project_python\NewN\NLP\outFile.txt','w',encoding="UTF-8")
Allword = open(r"E:\project_python\NewN\NLP\words.txt",'r',encoding="UTF-8")
testfile = open(r"E:\project_python\NewN\NLP\readFilesTest.txt",'w',encoding="UTF-8")

wordList = []
sentenceList = []
wordAndsentenceList = []
#把拿到的词放到list内
for word in Allword.readlines():
    word = word.strip()
    wordList.append(word)
for sentence in allFileTxt.readlines():
    sentence = sentence.strip()
    sentenceList.append(sentence)
# print(len(sentenceList))
def readFiles():
    i = 1
    for word in wordList:
        for sentence in sentenceList:
            if word in sentence:
                wordAndsentenceList.append([word,sentence])
    return wordAndsentenceList
readFiles()
#[词，[分词]]
list = util.solveSentences(wordAndsentenceList)
#拿到BIOList  list里面的句子标注BIO
BIOList = []
for alist in list:
    BIOList.append(util.BIO(alist))
print(len(list))
print(list,file=outFile)
#list [[词,[分词]],[词,[]].....]


#20914
BIOSentenceList = []
for list in list[0:1000]:
    BIOSentenceList.append(list[1])
# print(BIOSentenceList)
predict = loadedmodel.predict(BIOSentenceList)
# print(predict)
print(len(predict))
# print(len(BIOList))







